//
//  YCOrderModel.m
//  YCVillageDoctor
//
//  Created by zhangxiaoliang on 2017/7/27.
//  Copyright © 2017年 zhangxiaoliang. All rights reserved.
//

#import "YCOrderModel.h"
#import "YCOrderDetailViewController.h"

@implementation YCOrderModel
+(NSDictionary *) mj_replacedKeyFromPropertyName
{
    return @{
             @"createDate":@"CREATE_DATE",
             @"hzId":@"HZ_ID",
             @"memberName":@"MEMBER_NAME",
             @"predoutFlag":@"O2O_FLAG",
             @"orderId":@"ORDER_ID",
             @"orderMoney":@"ORDER_MONEY",
             @"orderName":@"ORDER_NAME",
             @"orderStatus":@"ORDER_STATUS",
             @"servePic":@"SERVE_PIC",
             @"sjName":@"SJ_NAME",
             @"sjType":@"SJ_TYPE"
             };
}

/**
 初始化模型的类型
 */
-(void)config
{
    /**
     对枚举进行数据初始化 YCOrderSJType YCOrderStatus
     */
    if ([self.orderName isEqualToString:@"在线咨询"]) {
        self.YCServerType=YCOrderSJType_OnlineConsultant;
    }else if([self.orderName isEqualToString:@"远程会诊"])
    {
        self.YCServerType=YCOrderSJType_RemoteConsultant;
    }else if([self.orderName isEqualToString:@"常规心电阅片"])
    {
        self.YCServerType=YCOrderSJType_ConventionalECGReading;
    }else if([self.orderName isEqualToString:@"动态心电阅片"])
    {
        self.YCServerType=YCOrderSJType_DynamicECGReading;
    }else if([self.orderName isEqualToString:@"患者根据处方订单下单"])
    {
        self.YCServerType=YCOrderSJType_Prescription;
    }else if([self.orderName isEqualToString:@"购买远程会诊服务"])
    {
        self.YCServerType=YCOrderSJType_BuyRemoteConsultant;
    }else if([self.orderName isEqualToString:@"购买百倍爱心卡"])
    {
        self.YCServerType=YCOrderSJType_BuyMutualFund;
    }
    
    if ([self.predoutFlag isEqualToString:@"已作废"]) {
        self.YCOrderStatus=YCOrderStatus_Cancel;
    }
    else if ([self.orderStatus isEqualToString:@"已付款"]) { // 对应着去核销
        self.YCOrderStatus=YCOrderStatus_DidPay;
        //购买远程会诊服务，在线咨询，购买互助资金是不能核销的,所以只能对应着变成消费成功的状态
        if (self.YCServerType & (YCOrderSJType_BuyRemoteConsultant|YCOrderSJType_OnlineConsultant|YCOrderSJType_BuyMutualFund)) {
            self.YCOrderStatus=YCOrderStatus_Success;
        }
    }else if([self.orderStatus isEqualToString:@"待付款"])
    {
        self.YCOrderStatus=YCOrderStatus_WaitPay;
    }else if([self.orderStatus isEqualToString:@"消费成功"]) // 对应着已完成
    {
        self.YCOrderStatus=YCOrderStatus_Success;
    }
    
}
//获取订单列表的数据
/*
 
 cl_TranModelArray 进行去空处理 将null变成 暂无数据
 
 */
-(void)sendPushMessageListRequest:(NSInteger)page OrderStatus:(YCOrderStatusParams)orderStatus O2OFlag:(YCO2OFlagParams)o2oFlag Success:(void(^)(id))success Failure:(void(^)(id))failure
{
    
    NSString *member_id = [[NSUserDefaults standardUserDefaults] objectForKey:KEXPERTID];
    NSString *url = [YCUrlManger sharedYCUrlManger].orderlistUrl;
    NSDictionary *params =@{
                            @"page_num":@(page),
                            @"member_id":member_id,
                            @"order_status":[self getOrderStatusParams:orderStatus]
                            };
    [[UIApplication sharedApplication].keyWindow presentLoadingTips:nil];
    [DownloadData post:url SerializerType:1 params:params success:^(id json) {
        [[UIApplication sharedApplication].keyWindow dismissTips];
        NSMutableArray* mutableArr=[NSMutableArray array];
        for (NSDictionary* dic in json) {
            YCOrderModel* model = [YCOrderModel mj_objectWithKeyValues:dic];
            [model config];
            [mutableArr addObject:model];
        }
        if (success) {
            success([self cl_TranModelArray:mutableArr modelName:NSStringFromClass([YCOrderModel class])]);
        }
    } failure:^(NSError *error) {
        [[UIApplication sharedApplication].keyWindow dismissTips];
        if (failure) {
            failure(error);
        }
    }];
}
#pragma 跳转到详情页面，如需网路请求的，可在此方法中添加相应的网络请求
-(void) DetailWithOrdelModel: (YCOrderModel *) order WithViewController: (UIViewController *)superController
{
    NSLog(@"点击进入详情");
//    XLOrderDetailViewController *  orVC =[[XLOrderDetailViewController alloc]init];
//    orVC.order = order;
//    [superController.navigationController pushViewController:orVC animated:YES];
    
}
- (id)getOrderStatusParams:(YCOrderStatusParams)params
{
    id orderStatus;
    
    switch (params) {
        case ORDERSTATUS_ZERO: //待付款
            orderStatus  = @0 ;
            break;
        case ORDERSTATUS_ONE:  //已付款
            orderStatus  = @1 ;
            break;
        case ORDERSTATUS_TWO: //已退款
            orderStatus  = @2 ;
            break;
        case ORDERSTATUS_NULL:
            orderStatus = @"" ;
            break;
        default:
            break;
    }
    return orderStatus ;
}
@end
